package com.property.manage.service.home;

import com.property.manage.model.home.HomeVo;
import com.property.manage.model.owner.OwnerCountVo;
import com.property.manage.service.equipment.EquipmentService;
import com.property.manage.service.fee.CollectionService;
import com.property.manage.service.flowingWater.ArrearsDetailService;
import com.property.manage.service.owner.OwnerService;
import com.property.manage.service.parking.ParkingService;
import com.property.manage.service.resource.BuildingService;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

@Service
public class HomeService {
    @Autowired
    private BuildingService buildingService;
    @Autowired
    private OwnerService ownerService;
    @Autowired
    private ParkingService parkingService;
    @Autowired
    private EquipmentService equipmentService;
    @Autowired
    private ArrearsDetailService arrearsDetailService;
    public HomeVo statistics(
            @ApiParam("小区id") @RequestParam(value = "villageId", required = false)Integer villageId){
        HomeVo homeVo = new HomeVo();
        homeVo.setBuilldingTotal(buildingService.getBuildingTotal(villageId));
        OwnerCountVo count = ownerService.findCount(villageId);
        if (count==null){
            homeVo.setOwnerTotal(0);
            homeVo.setHouseholds(0);
            homeVo.setTenantTotal(0);
        }else {
            homeVo.setHouseholds(count.getTotal());
            homeVo.setOwnerTotal(count.getOwnerTotal());
            homeVo.setTenantTotal(count.getTenantTotal());
        }
        homeVo.setVehiclesTotal(parkingService.getCount(villageId));
        Integer repairCount = equipmentService.getRepairCount(villageId);
        homeVo.setEquipmentCount(repairCount);
        Integer integer = arrearsDetailService.arrearsCount(villageId);
        homeVo.setCollectionCount(integer);
        homeVo.setMessageTotal(repairCount+integer);
        return homeVo;
    }

}
